﻿#include "CGame.h"
#include "CDefine.h"
#include "CInit.h"
#include "CAudioManager.h"
#include "CAudio.h"

void CGame::Run(HINSTANCE hInstance, int nShowCmd)
{
	CInit _cInit(wndHandle, hInstance, NAME, SCREENWIDTH, SCREENHEIGHT, ISFULLSCREEN);
	CAudioManager _cAudioManager;
	int done = 0;	

	// khởi tạo cửa sổ ứng dụng
	_cInit.initWindow(nShowCmd);
	
	_cInit.initSound();

	//khởi tạo đối tượng DirectX
	_cInit.initDirect3D();

	_cAudioManager.getInstance()->loadSound();

	// vòng lặp chính dùng để quản lý thông điệp:
	MSG msg;
	DWORD frame_start = GetTickCount();;
	
	DWORD tick_per_frame = 100 / 33;
	_cAudioManager.getInstance()->playSound(15);
	Sleep(1500);
	_cAudioManager.getInstance()->playSound(1);
	while (!done) 
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if (msg.message==WM_QUIT) done=1;

			TranslateMessage(&msg);
			DispatchMessage(&msg);			
		}

		DWORD now = GetTickCount();
		DWORD _DeltaTime = now - frame_start; 
		if (_DeltaTime >= tick_per_frame)
		{
			frame_start = now;
			_cInit.render();
		}
		
	}
	_cInit.~CInit();
	_cAudioManager.getInstance()->destroy();
}